package cn.sany.cterminal.common.utils;

import lombok.extern.slf4j.Slf4j;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
import javax.script.ScriptException;

/**
 *
 * @Project : forklift
 * @Package : cn.sany.forklift.common.utils
 * @Class : MathUtils
 * @Description : 计算工具类
 * @author : zhouxing
 * @CreateDate : 2020-08-13 11:57:18
 * @version : V0.5
 * @Copyright : 2020 sany.com Inc. All rights reserved.
 * @Reviewed :
 * @UpateLog :    Name    Date    Reason/Contents
 *             ---------------------------------------
 *                ****    ****    ****
 *
 */
@Slf4j
public class MathUtils {

    static ScriptEngineManager scriptEngineManager = new ScriptEngineManager();
    static ScriptEngine  scriptEngine = scriptEngineManager.getEngineByName("nashorn");
    public static String evalString(String formula){
        try {
            return String.valueOf(scriptEngine.eval(formula));
        } catch (ScriptException e) {
            log.error("计算字符串表达式异常：",e);
            return null;
        }
    }
}
